<template>
    <div>

        <Button type="success" @click="confirm()">删除</Button>
        <Modal
        v-model="modal"
        title="添加评论"
        width=850
        @on-ok="ok"
        @on-cancel="cancel">
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
                <FormItem label="ID" prop="name">
                    <Input v-model="formValidate.name" placeholder="Enter your ID"></Input>
                </FormItem>
                <FormItem label="Title" prop="title">
                    <Input v-model="formValidate.title" placeholder="Enter your title of news"></Input>
                </FormItem>
                <FormItem label="Desc" prop="desc">
                    <!-- <Input v-model="formValidate.desc" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="Enter something..."></Input> -->
                    <quill-editor v-model="formValidate.desc"
                      ref="myQuillEditor"
                      >
                    </quill-editor>
                </FormItem>
                <FormItem>
                    <Button type="primary" @click="handleSubmit('formValidate')">Submit</Button>
                    <Button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">Reset</Button>
                </FormItem>
            </Form>
        </Modal>

        <i-input icon="search" placeholder="请输入..." style="width: 350px" @on-click="search()" v-model="filter.name"></i-input>
        <Table border :columns="columns" :data="list" @on-selection-change="addSelectData($event)"></Table>
        <Page :total="total" show-total show-sizer show-elevator :page-size=5 :page-size-opts="arr" @on-change="pageChange($event)" @on-page-size-change="pageSizeChange($event)"></Page>
    </div>
</template>
<script>
    import  Base from './Base'

    // require styles
    import 'quill/dist/quill.core.css'
    import 'quill/dist/quill.snow.css'
    import 'quill/dist/quill.bubble.css'
    import { quillEditor } from 'vue-quill-editor'


    export default {
        mixins: [Base],
        data () {
            return {
                module:"comment",
                columns: [
                       { type: 'selection',
                        width: 60,
                        align: 'center'
                        },
                    {
                        title: 'ID',
                        key: 'name',
                        render: (h, params) => {
                            return h('div', [
                                h('Icon', {
                                    props: {
                                        type: 'person'
                                    }
                                }),
                                h('strong', params.row.name)
                            ]);
                        }
                    },
                     {
                        title: '新闻',
                        key: 'title'
                    },
                    {
                        title: '评论内容',
                        key: 'desc'
                    },
                    {
                      title:'评论时间',
                      key:'date'
                    },
                    {
                        title: 'Action',
                        key: 'action',
                        width: 200,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.show(params.index)
                                        }
                                    }
                                }, '查看'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.index)
                                        }
                                    }
                                }, '删除'),
                                h('Button', {
                                    props: {
                                        type: 'warning',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            this.type="change";
                                            this.modal=true;
                                            this.formValidate={...(this.list[params.index])};
                                        }
                                    }
                                }, '修改')
                            ]);
                        }
                    }
                ],
                filter:{
                        page:1,
                        limit:0,
                        name: ""
                },
                showCheckbox: true,
                  modal: false,
                  formValidate: {
                    name: '',
                    title:'',
                    desc: '',
                    date:Date.now
                },
                ruleValidate: {
                    name: [
                        { required: true, message: 'The name cannot be empty', trigger: 'blur' }
                    ],
                    title: [
                        { required: true, message: 'Please enter a personal introduction', trigger: 'blur' },
                        { type: 'string', min: 10, message: 'Introduce no less than 10 words', trigger: 'blur' }
                    ],
                    desc: [
                        { required: true, message: 'Please enter a personal introduction', trigger: 'blur' },
                        { type: 'string', min: 20, message: 'Introduce no less than 20 words', trigger: 'blur' }
                    ]
                }

            }
        },
        methods: {
            show (index) {
                this.$Modal.info({
                    title: 'Comment Info',
                    content: `Name：${this.list[index].name}<br>title：${this.list[index].title}<br>Desc：${this.list[index].desc}<br>Date：${this.list[index].date}`
                })
            },
        },
        components: {
          quillEditor
        }
    }
</script>
